package com.swing.gui.component.popups.second;

import base.JPopupMenuBase;
import com.swing.gui.component.popups.LockMenu;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * @author Yuang, Gongming
 * @date 2022-01-24 13:25
 */
public class Dome extends JMenu implements JPopupMenuBase {

    private static Dome dome;

    private static JMenuItem test;

    public static Dome init() {
        if (dome == null) {
            synchronized (Dome.class) {
                if (dome == null) {
                    dome = new Dome();
                    try {
                        dome.instance();
                        dome.style();
                        dome.listener();
                        dome.loading();
                    } catch (Exception e) {
                        throw new RuntimeException(Dome.class.getSimpleName() + " initialization failed");
                    }

                }
            }
        }
        return dome;
    }

    public void instance() {
        dome.setText("二级菜单");
        test = new JMenuItem("测试");
    }

    public void style() {
        dome.setBackground(Color.WHITE);
        test.setBackground(Color.WHITE);
    }

    public void listener() {
        test.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(null, test.getText());
            }
        });
    }

    public void loading() {
        dome.add(test);
    }

}
